using System;
using System.Data;
using System.IO;
using System.Web;
using System.Xml;
using Framework.Library.Core.Config;

namespace Framework.Library.Core.Utils.GlobalHelper
{
    internal class StaticDataHelper
    {
        public static DataTable Languages()
        {
            using (var dt = new DataTable("Languages"))
            {
                dt.Columns.Add("Language", typeof (string));
                dt.Columns.Add("FileName", typeof (string));
                var cfg = new Configurations();
                var dir =
                    new DirectoryInfo(HttpContext.Current.Request.MapPath(String.Format("{0}Languages", Configurations.ROOTDIR)));
                FileInfo[] files = dir.GetFiles("*.xml");
                foreach (FileInfo file in files)
                {
                    try
                    {
                        var doc = new XmlDocument();
                        doc.Load(file.FullName);
                        DataRow dr = dt.NewRow();
                        dr["Language"] = doc.DocumentElement.Attributes["language"].Value;
                        dr["FileName"] = file.Name;
                        dt.Rows.Add(dr);
                    }
                    catch (Exception)
                    {
                    }
                }
                return dt;
            }
        }

        public static DataTable AllowDisallow()
        {
            using (var dt = new DataTable("AllowDisallow"))
            {
                dt.Columns.Add("Text", typeof (string));
                dt.Columns.Add("Value", typeof (int));

                string[] tTextArray = {"Allowed", "Disallowed"};

                for (int i = 0; i < tTextArray.Length; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["Text"] = tTextArray[i];
                    dr["Value"] = i;
                    dt.Rows.Add(dr);
                }
                return dt;
            }
        }
    }
}